package com.marvin.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.marvin.core.Blog;
import com.marvin.mapper.BlogMapper;
import com.marvin.service.IArchiveService;
import com.marvin.vo.ArticleWithYear;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;
import java.util.TreeMap;

/**
 * @author yinyin
 * @create 2021/12/06 上午 9:53
 */
@Controller
public class ArchivesController {
    @Autowired
    private IArchiveService archiveService;



    @GetMapping("archives")
    public String toArchives(){
        return "/archives/archives";
    }

    @ResponseBody
    @GetMapping("api/archive/load")
    public TreeMap<Integer, List<Blog>> queryBlogList(){
        return archiveService.queryBlogs();
    }

    @ResponseBody
    @GetMapping("api/archive/loadToVo")
    public List<ArticleWithYear> queryBlogListVo(){
        return archiveService.queryBlogs2();
    }

    //@ResponseBody
    //@GetMapping("getYear/{currentPage}")
    //public List<Map<String,Object>> getYear(@PathVariable Integer currentPage){
    //    return archiveService.queryYear();
    //}
    @ResponseBody
    @GetMapping("getYear")
    public List<Map<String,Object>> getYear(){
        return archiveService.queryYear();
    }

    //分页根据年份查询
    @ResponseBody
    @GetMapping("loadMore/{pageNumber}/{pageSize}/{year}")
    public List<Blog> loadMore(@PathVariable Integer pageNumber,@PathVariable Integer pageSize,@PathVariable Integer year){
        IPage<Blog> blogYear = archiveService.getBlogYear(pageNumber, pageSize, year);
        List<Blog> records = blogYear.getRecords();
        return  records;
    }



}
